package com.ykdl.member.kid.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.Toast;

import com.tencent.mm.sdk.openapi.IWXAPI;
import com.ykdl.member.kid.R;
import com.ykdl.member.constant.KidAction;
import com.ykdl.member.kid.gears.ShareWeiBo;

public class ShareUtil {
	
	private Dialog share_dialog;
	private Activity context;
	public ShareUtil(Activity context){
		this.context = context;
	}
	public void show(final String content) {
		 share_dialog = new Dialog(context, R.style.bubble_dialog);
		 share_dialog.setCanceledOnTouchOutside(true);
		Window dialogWindow = share_dialog.getWindow();
		WindowManager manager = context.getWindowManager();
		LayoutParams params = dialogWindow.getAttributes();// 获取LayoutParams
		dialogWindow.setGravity(Gravity.BOTTOM);
		params.width = manager.getDefaultDisplay().getWidth();
		dialogWindow.setAttributes(params);
		share_dialog.setContentView(R.layout.topic_tools);
		share_dialog.show();
		share_dialog.findViewById(R.id.share_weibo).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				initWeiBo(content);
			}
		});
		share_dialog.findViewById(R.id.share_weixin).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				initWeiXin(content);
			}
		});
		share_dialog.findViewById(R.id.topic_report).setVisibility(View.GONE);
		share_dialog.findViewById(R.id.cance).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				share_dialog.dismiss();
			}
		});
	}
	
	
	private void initWeiBo(String coment) {
		String sharecontent = null ;
		try {
			Intent t = new Intent(context, ShareWeiBo.class);
			sharecontent = "我在辣妈育儿，快来围观吧！" + coment
					+ "，【苹果、安卓手机免费下载】http://www.ykdllmyr.com/lmyr/apk/lmyr_latest.apk";
			t.putExtra(KidAction.SHARE_TIP, sharecontent);
			context.startActivity(t);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void initWeiXin(String coment) {
//		IWXAPI api = WeiXinUtil.getWXAPIFactoryAndReg(context);
//		int supportAPI = api.getWXAppSupportAPI();
//		if (supportAPI==0) {
//			Toast.makeText(context, "未安装微信！", 1).show();
//		}else {
//			WeiXinUtil weixin = new WeiXinUtil(context, api);
//		    weixin.shareWXWebToGroup("我在辣妈育儿，快来围观吧！",coment, null,null,true);
//		}
//		
	}
}
